package com.yc.javaee.tomcat.impl;

import com.yc.javaee.tomcat.HttpServlet;
import com.yc.javaee.tomcat.HttpServletRequest;
import com.yc.javaee.tomcat.HttpServletResponse;
import com.yc.javaee.tomcat.ServletException;

import java.io.IOException;

public abstract class HttpServletImpl implements HttpServlet {

    // service 负责分发请求
    @Override
    public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        switch (request.getMethod()){
            case "GET": doGet(request,response); break;
            case "POST": doPost(request,response); break;
            case "OPTIONS": doOptions(request,response); break;
            case "HEAD": doHead(request,response); break;
            case "TRACE": doTrace(request,response); break;
        }
    }

    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        throw new ServletException("405错误, 该方法未实现");
    }

    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        throw new ServletException("405错误, 该方法未实现");
    }

    @Override
    public void doOptions(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        throw new ServletException("405错误, 该方法未实现");
    }

    @Override
    public void doPut(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        throw new ServletException("405错误, 该方法未实现");
    }

    @Override
    public void doHead(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        throw new ServletException("405错误, 该方法未实现");
    }

    @Override
    public void doTrace(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        throw new ServletException("405错误, 该方法未实现");
    }

    @Override
    public void init() {

    }

    @Override
    public void destroy() {

    }
}
